package it.mauriziobasile.andoid.aub.runnable;

import it.mauriziobasile.andoid.aub.AdvUniversalBlockerActivity;
import it.mauriziobasile.andoid.aub.su.RootUtils;
import it.mauriziobasile.andoid.aub.utils.Logger;

import java.io.IOException;

import android.content.Context;

public class Restore extends BaseRunnable {

    public Restore(Context context) {
        super(context);
    }

    public void run() {
        try {
            int exit = RootUtils.restoreHostsFile();
            if (exit == 0) {
                notifyMessage("Original file restored up!", AdvUniversalBlockerActivity.MSG_ACTION);
            } else {
                notifyMessage("ERROR restoring original hosts file " + exit, AdvUniversalBlockerActivity.MSG_ACTION);
            }
        } catch (IOException e) {
            Logger.e("ERRORE " + e.getMessage());
            notifyMessage("ERROR restoring original hosts file " + e.getMessage(), AdvUniversalBlockerActivity.MSG_ACTION);
        } catch (InterruptedException e) {
            notifyMessage("ERROR restoring original hosts file " + e.getMessage(), AdvUniversalBlockerActivity.MSG_ACTION);
            Logger.e("ERRORE " + e.getMessage());
        }
    }

}
